﻿using System;
using System.Collections.Generic;
using System.IO;

namespace picomp
{
    internal class ZipRecce
    {
        public ZipRecce()
        {
            ZipFiles = new List<string>();
        }

        public List<string> ZipFiles { get; private set; }

        private void AddFile(string file)
        {
            if (ZipFiles.IndexOf(file) == -1)
                ZipFiles.Add(file);
            Console.WriteLine("Queued " + Path.GetFileName(file));
        }

        public void ScanFolder(string folder)
        {
            ZipFiles.Clear();
            foreach (var file in Utilities.GetZipArchives(folder))
            {
                try
                {
                    var firstVol = Utilities.LocateFirstVolume(file);
                    if (string.IsNullOrEmpty(firstVol))
                    {
                        AddFile(file);
                    }

                    if (string.Compare(firstVol, file, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        AddFile(file);
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Error processing {0}", Path.GetFileName(file));
                }
            }
        }
    }
}